import { request } from '@/utils/request';
// 知识库详情页相关的接口

/**
 * 根据知识库id查询该知识库下的所有文档列表
 * @returns {Promise<ApiRet>}
 */
const getDocListOfKnowledgeBase = (knowledgeBaseId) => {
  return request({
    url: '/doc/getDocListOfKnowledgeBase',
    method: 'GET',
    params: { knowledgeBaseId }
  });
};

/**
 * 根据文档id查询文档详情
 * @returns {Promise<ApiRet>}
 */
const getDocDetailsByDocId = (docId) => {
  return request({
    url: '/doc/getDocDetailsByDocId',
    method: 'GET',
    params: { docId }
  });
};

/**
 * 根据文档id及权限获取文档分享码
 * @returns {Promise<ApiRet>}
 */
const getDocShareCode = (docId, docPermission) => {
  return request({
    url: '/doc/getDocShareCode',
    method: 'GET',
    params: {
      docId,
      docPermission
    }
  });
};

/**
 * 校验文档分享码并获取文档详情
 * @returns {Promise<ApiRet>}
 */
const verifyDocShareCode = (shareCode) => {
  return request({
    url: '/doc/verifyDocShareCode',
    method: 'GET',
    params: {
      shareCode
    }
  });
};

/**
 * 新建、编辑保存文档详情信息
 * @returns {Promise<ApiRet>}
 */
const saveDocMessage = (data) => {
  return request({
    url: '/doc/saveDocMessage',
    method: 'POST',
    data
  });
};

/**
 * 根据文档id删除文档
 * @param {string} docId 文档id
 */

const deleteDoc = ({ docId }) => {
  const params = {
    docId
  }
  return request({
    url: '/doc/deleteDocByDocId',
    method: "DELETE",
    params
  })
}

/**
 * 根据知识库id查询非当前知识库的文档
 * @param {string} docId 文档id
 */

const findDocOutOfKnowledgeBase = ({ knowledgeBaseId }) => {
  return request({
    url: `/doc/findDocOutOfKnowledgeBase/${knowledgeBaseId}`,
    method: "GET",
  })
}

/**
 * 根据文档id导入文档至知识库
 * @param {string} docId 文档id
 */

// src/views/KnowledgeBase/pages/detail/component/api.js
const inputDocIntoKnowledgeBase = ({ knowledgeBaseId, docIdList }) => {
  return request({
    url: `/doc/inputDocIntoKnowledgeBase/${knowledgeBaseId}`,
    method: "POST",
    data: docIdList
  });
};

/**
 * 根据文档id及知识库id将文档移出知识库
 * @param {string} docId 文档id
 */

const removeDocFromKnowledgeBase = ({ knowledgeBaseId, docIdList }) => {
  return request({
    url: `/doc/removeDocFromKnowledgeBase/${knowledgeBaseId}`,
    method: "DELETE",
    data: docIdList
  });
};

export {
  getDocListOfKnowledgeBase,
  getDocDetailsByDocId,
  getDocShareCode,
  verifyDocShareCode,
  saveDocMessage,
  deleteDoc,
  findDocOutOfKnowledgeBase,
  inputDocIntoKnowledgeBase,
  removeDocFromKnowledgeBase
}